﻿var num = 4;
var tim;
var count = 3;
var submitTime;
var pageTime;

window.onbeforeunload = ShowPageLoadingProgress; 

function HideLoading() 
{
    if (num == 5) {
    document.getElementById('divLoading').style.display = "none";
    document.getElementById('divContent').style.display = "";
    window.clearTimeout(tim);
    }
    else {
        count--;
        document.getElementById('divMessage').innerHTML = " Please wait ...";//" + count.toString() + " seconds...";
        tim = window.setTimeout("HideLoading()", 1000);
        
    }
    num ++;
}

function IncreaseProgress(valPercent)
{
    document.getElementById('divPgrPercent').innerHTML = valPercent.toString() + "%";
    //document.getElementById('pgrBar').style.width= valPercent.toString() + "%";
}



function ShowSubmitLoading()
{
    /*document.getElementById('divPageLoading').style.display = "none";
    document.getElementById('divSubmitLoading').style.display = "";
    window.clearTimeout(submitTime);
    submitTime =  window.setTimeout("ChangeSubmitMessage()", 5000);*/
}

function ChangeSubmitMessage()
{
    document.getElementById('divLoadingMessage').innerHTML = "Still loading...";
    window.clearTimeout(submitTime);
}

function StopSubmit()
{
    document.getElementById('lnkStop').style.display = "none";
    document.getElementById('divLoadingMessage').innerHTML = "Stopping request...";
    if(navigator.appName == "Microsoft Internet Explorer")
    {
        window.document.execCommand('Stop');
    }
    else
    {
        window.stop();
    }
    
    window.location.reload(false);
    submitTime =  window.setTimeout("HideSubmitLoading()", 1000);
    document.getElementById('divLoadingMessage').innerHTML = "Cancelling request...";
}

function HideSubmitLoading()
{
    document.getElementById('divSubmitLoading').style.display = "none";
    window.clearTimeout(submitTime);
}    
        
function ShowSubmitProgress(validationGroup)
{
    var IsPageValid = Page_ClientValidate(validationGroup);
    
    //alert(IsPageValid);
    if (IsPageValid != null && IsPageValid == true) 
    {
        //submitTime =  window.setTimeout("ShowSubmitLoading()", 2000);
    }
    else
    {
        //submitTime =  window.setTimeout("HideSubmitLoading()", 500);
        //alert("HideSubmitLoading");
    }
}

function ShowPageLoadingProgress()
{
    pageTime =  window.setTimeout("ShowPageLoading()", 1000);
    //return true;
}

function ShowPageLoading() {
    try {
        document.getElementById('divPageLoading').style.display = "";
        document.getElementById('lnkPageStop').style.display = "none";
        document.getElementById('divPageLoadingMessage').innerHTML = "Loading...";
        window.clearTimeout(pageTime);
        pageTime = window.setTimeout("ChangePageLoadingMessage()", 5000);
    }
    catch (ex) {
        //alert(ex.toString());
    }
}

function StopPageLoading()
{
    document.getElementById('lnkPageStop').style.display = "none";
    document.getElementById('divPageLoadingMessage').innerHTML = "Stopping request...";
    if(navigator.appName == "Microsoft Internet Explorer")
    {
        window.document.execCommand('Stop');
    }
    else
    {
        window.stop();
    }
    
    //window.location.reload(false);
    pageTime =  window.setTimeout("HidePageLoading()", 1000);
    document.getElementById('divPageLoadingMessage').innerHTML = "Cancelling request...";
}

function HidePageLoading()
{
    document.getElementById('divPageLoading').style.display = "none";
    document.getElementById('divPageLoadingMessage').innerHTML = "Loading...";
    document.getElementById('lnkPageStop').style.display = "none";
    window.clearTimeout(pageTime);
} 

function ChangePageLoadingMessage()
{
    document.getElementById('divPageLoadingMessage').innerHTML = "Still loading...";
    window.clearTimeout(pageTime);
    pageTime =  window.setTimeout("HidePageLoading()", 60000);
}